﻿/*
 * Copyright 2012 Rene Prost, Registrite ja Infosüsteemide Keskus 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Text;
using System.Web;
using NUnit.Framework;
 
using Xtee.Core.Mime.Message;

namespace Xtee.Core.Test
{
    [TestFixture]
    public class UtilsTest : TestBase

    {
      
        [Test]
        public void TestHeaderCopyToSoapMessage()
        {
         //MultipartSoapUtils

            NameValueCollection coll = new NameValueCollection();
              SoapMessage mess = new SoapMessage(null);
       
          
            coll.Add("Content-Type","text/xml");
            coll.Add("CustomHeader", "myvalue"); //should not copy
            coll.Add("Accept", "this shouldn copy ");
            MultipartSoapUtils.CopyHeaders(coll, mess);

            Assert.That(mess.Headers.Count,Is.EqualTo(2)); //content transfer encoding is default added
         
        }
        [Test]
        public void HttpHeadersCopy_HttpWebRequestTest()
        {
            HttpWebRequest request = (HttpWebRequest) HttpWebRequest.Create("http://localhost/notrelevant");
            SoapMessage mess = new SoapMessage(null);
            NameValueCollection coll = GetTestHeaders();

            Console.WriteLine(request.Headers.Count);
            MultipartSoapUtils.CopyHeaders(coll, request);
            
        }
      
      

        private NameValueCollection GetTestHeaders()
        {
            NameValueCollection coll = new NameValueCollection();
       

            coll.Add("Content-Type", "text/xml");

            coll.Add("Content-Encoding", "dummy");
            coll.Add("Content-Length", "dummy");
            coll.Add("Content-Disposition", "dummy");
            coll.Add("Content-Type", "dummy");
            coll.Add("Content-Transfer-Encoding", "dummy");
            coll.Add("Content-Disposion", "dummy");
            coll.Add("Content-Description", "dummy");
            coll.Add("MIME-Version", "dummy");
            coll.Add("SoapAction", "dummy");

            coll.Add("CustomHeader", "myvalue");
            coll.Add("Accept", "this shouldn copy ");
            coll.Add("User-Agent", "dummy");
            coll.Add("Referer", "dummy");
            coll.Add("Accept", "dummy");
            coll.Add("Host", "dummy");
            coll.Add("Expect", "dummy");
            coll.Add("Configuration", "dummy");
            coll.Add("Keep-Alive", "dummy");
            coll.Add("Close", "dummy");
            return coll;
        }
    }
}
